package com.company.project.common.job.task;

import com.company.project.entity.SysUser;
import com.company.project.mapper.SysUserMapper;
import com.company.project.mapper.TThrbMapper;
import com.company.project.mapper.TWdkhMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;

/**
 * 通话日报统计 每小时一次
 * testTask为spring bean的名称， 方法名称必须是run
 *
 * @author wenbin
 * @version V1.0
 * @date 2020年3月18日
 */
@Component("mxs01Task")
public class Mxs01Task {
	private Logger logger = LoggerFactory.getLogger(getClass());

	@Resource
	private SysUserMapper sysUserMapper;

	@Resource
	private TThrbMapper tThrbMapper;
	@Resource
	private TWdkhMapper tWdkhMapper;

	public void run(String params) {
		logger.debug("insertThjl 每小时一次定时任务正在执行，开始：{}", params);
		LocalTime now = LocalTime.now();
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH");
		String currentTime = now.format(formatter) + ":00";
		String type = "小时";

		tThrbMapper.insertThjl(currentTime, type, "ydhxtr", "");
		//代理商
		List<SysUser> sysUsers = tThrbMapper.selectDls();
		for (SysUser user : sysUsers) {
			tThrbMapper.insertThjl(currentTime, type, user.getUsername(), user.getUsername());
		}
		logger.debug("insertThjl 每小时一次定时任务正在执行，结束：{}", params);

		logger.debug("insertTKhtj 每小时一次定时任务正在执行，开始：{}", params);
		//我的客户统计 新增客户和新增意向度客户AB
		List<String> users = tWdkhMapper.selectSsxsAll();
		for (String user : users) {
			String khsl = tWdkhMapper.selectKhsl(user);
			String yxdsl = tWdkhMapper.selectYxdsl(user);
			tWdkhMapper.insertTKhtj(khsl, yxdsl, currentTime, type, user);
		}
		logger.debug("insertTKhtj 每小时一次定时任务正在执行，结束：{}", params);

	}

	private void tjwdkh() {
		LocalTime now = LocalTime.now();
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH");
		String time = now.format(formatter) + ":00";
		String type = "小时";
		List<String> users = tWdkhMapper.selectSsxsAll();
		for (String user : users) {
			String khsl = tWdkhMapper.selectKhsl(user);
			String yxdsl = tWdkhMapper.selectYxdsl(user);
			tWdkhMapper.insertTKhtj(khsl, yxdsl, time, type, user);
		}
	}
}
